import { defineStore } from 'pinia'
import { getCategoryInfo, getshopList, reqGetPhone } from '@/api/category'
import { getGoodsList } from '@/api/category'

export const useCategoryStore = defineStore('category', {
  state: () => {
    return {
      category1: [],
      category2: [],
      category3: [],
      categoryL1List: [],
      categoryL2List: [],
      currentCategory: [],
      categoryGroupList: [],
      categoryItems: [],
      categoryL1: [],
      id: '',
      categoryView: {},
      skuInfo: [],
      price:''
      
    }


  },
  actions: {
    async getCategory() {
      try {
        const res: any = await getCategoryInfo()
        // console.log(7878, res);
        this.category1 = res.categoryL1List,
          this.category2 = res.categoryL2List,
          this.category3 = res.currentCategory
      } catch (error) {
        return ('获取失败')
      }
    },
    async getrightList(index: number) {
      const result: any = await getGoodsList(index);
       console.log(result, 11111);
      this.categoryL1List = result.categoryL1List,
        this.categoryL2List = result.categoryL2List
      this.currentCategory = result.currentCategory
      this.categoryGroupList = result.categoryGroupList

    },
    async shopList(id1: number, id2: number) {
      const result: any = await getshopList(id1, id2)
      console.log('111111', result);
      this.categoryItems = result.categoryItems,
        this.categoryL1 = result.categoryL1,
        this.categoryL2List = result.categoryL2List
      this.id = result.categoryL1.id
      // console.log(12121, result.categoryL1.id);

      // console.log(result.categoryItems.itemList);
      // console.log(result.categoryItems.itemList[0].finalPriceInfoVO);

    },
   

    async getPhone(skuId: number) {
      const result:any = await reqGetPhone(skuId)
      this.categoryView = result.categoryView
      this.skuInfo = result.skuInfo
      this.price    = result.price
      console.log(result);
    },

  }

})

